﻿using Godot.core.os;
using Godot.core;

namespace Godot.platform.stub
{
    public partial class FileAccessStub : FileAccess
    {
        protected override Error _open(string p_path, int p_mode_flags)
        {
            try
            {
                __file = new System.IO.FileStream(p_path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                return Error.OK;
            }
            catch (System.Exception ex)
            {
                __file = null;
                return Error.FAILED;
            }
        }

        protected override ulong _get_modified_time(string p_file)
        {
            throw new System.NotImplementedException();
        }

        public override void close()
        {
            __file.Close();
            __file.Dispose();
        }

        public override void is_open()
        {
            throw new System.NotImplementedException();
        }

        public override void seek(uint p_position)
        {
            __file.Seek(p_position, System.IO.SeekOrigin.Begin);
        }

        public override void seek_end(long p_position = 0)
        {
            throw new System.NotImplementedException();
        }

        public override uint get_pos()
        {
            throw new System.NotImplementedException();
        }

        public override uint get_len()
        {
            throw new System.NotImplementedException();
        }

        public override bool eof_reached()
        {
            return __file.Position == __file.Length;
        }

        public override Error get_error()
        {
            throw new System.NotImplementedException();
        }

        public override byte get_8()
        {
            return (byte) __file.ReadByte();
        }

        public override int get_buffer(byte[] p_buffer, int p_length)
        {
            return __file.Read(p_buffer, 0, p_length);
        }

        public override void store_8(byte p_dest)
        {
            throw new System.NotImplementedException();
        }

        public override bool file_exists(string p_name)
        {
            throw new System.NotImplementedException();
        }

        private System.IO.FileStream __file;
    }
}
